package com.cp.mtq.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class MtqIndexController {

    @RequestMapping("/")
    public void index(HttpServletResponse response) throws IOException {
        response.sendRedirect("http://tuoguanjy.cn/mtq/static/page/modelList.html");
    }

    @Value("${account}")
    private String account;
    @Value("${password}")
    private String password;

    @PostMapping("/doLogin")
    @ResponseBody
    public boolean doLogin(String logname, String logpass, HttpServletRequest request){


        String[] acc = account.split(",");
        String[] pass = password.split(",");
        for(int i=0;i<acc.length; i++){
            if(logname.equals(acc[i])){
                request.getSession().setAttribute("mtqToken", acc[i]);

                if(logpass.equals(pass[i])) return true;
            }
        }
        return false;
    }
}
